package sample.controller.todo;

import java.util.logging.Logger;
import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;
import org.slim3.datastore.Datastore;
import org.slim3.util.StringUtil;

import com.google.appengine.api.datastore.KeyFactory;

public class DeleteController extends Controller {

    @SuppressWarnings("unused")
    private static final Logger logger = Logger.getLogger(DeleteController.class.getName());

    @Override
    public Navigation run() {
        Integer page = asInteger("page");
        if (page == null) page = 0;
        String key = asString("key");
        if (!StringUtil.isEmpty(key)) {
            Datastore.delete(KeyFactory.stringToKey(key));
        }
        return redirect(basePath + "?page=" + page);
    }
}
